/**
 * 库存价格查询DataUtility
 * 
 * @author 魏文杰 
 * @Version 1.0
 * @Date 2013-10-08
 */

package ext.generic.erp.datautilities;

import wt.util.WTException;

import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.AbstractDataUtility;
import com.ptc.mvc.util.ClientMessageSource;
import com.ptc.mvc.util.ResourceBundleClientMessageSource;

import ext.generic.erp.bean.GenericIEBean;
import ext.generic.erp.rule.BussinessRule;

public class QueryInventoryPriceDataUtility extends AbstractDataUtility {
	private static final String RESOURCE = "ext.generic.erp.manually.IntegrationResource";
	private static ClientMessageSource messageSource = new ResourceBundleClientMessageSource(RESOURCE);
	
	@Override
	public Object getDataValue(String param , Object object, ModelContext modelContext) throws WTException {
		
//		System.out.println(">>>>> Entering in QueryInventoryPriceDataUtility.getDataValue(String param , Object object, ModelContext modelContext)") ;
//		
//		System.out.println("param = " + param ) ;
		
		Object obj = null ;
		
		if ( object != null && object instanceof GenericIEBean ) {
			GenericIEBean genericIEBean = ( GenericIEBean ) object ;
			
			if(param.equals("number")){
				obj = genericIEBean.getAttribute("item_id") ;
			}else if(param.equals("name")){
				obj = genericIEBean.getAttribute("item_name") ;
			}else if(param.equals("orgCode")){
				obj = genericIEBean.getAttribute("org_code") ;
			}else if(param.equals("partPrice")){
				//如果可以查看价格信息，则显示，否则显示没有权限
				if( BussinessRule.canReadPrice() ){
					obj = genericIEBean.getAttribute("price") ;
				}else{
					//obj = CommonConstant.NO_PRIVILEGE ;
					obj = messageSource.getMessage("QUERY_INVENTORY_PRICE_TABLE_NO_PRIVILEGE") ;
				}
			}else if(param.equals("partInventory")){
				obj = genericIEBean.getAttribute("qty_onhand") ;
			}else if(param.equals("unit")){
				obj = genericIEBean.getAttribute("unit") ;
			}else{
				obj = "" ;
			}
		}else{		
			if(object != null){
				System.out.println("Object type is " + object.getClass()) ;
			}else{
				System.out.println("Object is NULL!") ;
			}
		}
		
//		System.out.println("<<<<< Existing in QueryInventoryPriceDataUtility.getDataValue(String param , Object object, ModelContext modelContext)") ;
		
		return obj;
	}
}
